<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<%--系统组织机构列表 --%>
		<base href="<%=basePath%>">
		<title>${title}</title>
		<link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/common.css'/>"/>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery-1.7.2.min.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery.form.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/artdialog/artdialog.js?skin=${sys_theme}'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/artdialog/iframetools.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/js/common.js'/>"></script>
		<script type="text/javascript">
			$(function(){
				//界面初始化
				initView();
				$("#tbl_datalist tr:even").css({"background-color":"#f2f7fd"});
				var _tmp_bg = "#fff";
				$("#tbl_datalist tr").hover(function() {
					_tmp_bg = $(this).css("background-color");
					$(this).css("background-color", "#cce3c7");
				}, function() {
					$(this).css("background-color", _tmp_bg);
				});
				//窗体更改监听 
				$(window).resize(function(){
					initView();
				});
			});
			/**页面跳转通用方法*/
			function goto_page(pageIndex){
				var url = window.location.toString();
				if(url.indexOf("/fuzzyQuery/")>0){
					$("form").attr("action","dept/fuzzyQuery/"+pageIndex+".html");
					$("#deptId").val("${deptid}");
					$("#deptName").val("${deptName}");
					$("form").submit();
				}else{
					if("${deptId}"==""||"${deep}"=="")
						return;
					window.location.href="<c:url value='/dept/query/${deptId}/@/${deep}.html'/>".replace("@",pageIndex);
				}
			}
			//根据条件查询部门信息
			function search(){
				var deptId = $.trim($("#deptId").val());
				var deptName = $.trim($("#deptName").val());
				$("#searchForm").submit();
			}
			//关闭窗口
			function tipclose(content,parentId){
				art.dialog.tips(content, 1.5);
				window.setTimeout(function(){
					window.location.reload();
					window.parent.refreshTree(parentId,'delete');
				},1500);
			}
			//移除部门
			function deleteDept(deptId,parentId){
				art.dialog.confirm("是否确认删除当前部门?",function(){
					$.ajax({
						url:"dept/deletedept/"+deptId+".json",
						success:function(result){
							switch(result.msg){
							case 0:
								tipclose("删除成功!",parentId);
								break;
							case 1:
								art.dialog.tips("含有下级部门，删除失败!");
								break;
							case 2:
								art.dialog.tips("部门人员不为空，删除失败!");
								break;
							default :art.dialog.tips("错误");break;
							}
						},
						error:function(){
							art.dialog.tips("删除失败!");
						}
				});
				});
			}
			//界面初始化
			function initView(){
				$("#tbl_container").css({"height":$(window).height()-85,"width":$(window).width()});
				$("#div_nav").css({"width":$(window).width()});
				if($(window).width()<860){
					$("#tbl_datalist tr:gt(0)").each(function(index,obj){
						$(this).find(".name1").text(function(){
							var _tmp = $(this).text();
							return _tmp.length>=8?_tmp.substring(0,8)+"...":_tmp;
						});
					});
				}else{
					$("#tbl_datalist tr:gt(0)").each(function(index,obj){
						$(this).find(".name1").text(function(){
							var _tmp = $(this).text();
							return _tmp.length>=10?_tmp.substring(0,10)+"...":_tmp;
						});
					});
				}
			}
			function re_set(){
				$("#deptId,#deptName").val("");
			}
		</script>
	</head>
	<body style="margin:0 auto;">
	<div>
		<div style="height:45px;line-height:45px;">
			<form class="app_form_query" id="searchForm" action="dept/fuzzyQuery/1.html">
	    		<ul class="list_title form_ul" style="width:100%;">
	    			<li style="width:55px;text-aling:right;padding-left:5px;">部门编号</li>
	    			<li class="l3" style="width:120px;"><input type="text" id="deptId" value="${deptid}" maxlength="12" name="deptId" onblur="this.value=this.value.replace(/[^0-9]/g,'');" style="width:120px;height:18px;padding:1px;"></li>
	    			<li style="width:55px;text-aling:right;padding-left:10px;">部门名称</li>
	    			<li class="l3" style="width:130px;text-align:left;"><input type="text" id="deptName" value="${deptName}" maxlength="18" name="deptName"  onblur="this.value=this.value.replace(/[^\w\b\u4e00-\u9fa5]/g,'');" style="width:120px;height:18px;padding:1px;"></li>
	    			<li><button class="mac_btn2" onclick="search();">查  询</button></li>
	    			<li><button class="mac_btn2" onclick="re_set();">重  置</button></li>
	    			<li><button class="mac_btn2" onclick="parent.addDept('${deptId}');return false">新  增</button></li>
	    		</ul>
	    	</form>
	   	</div>
	   
	   	<div id="tbl_container">
	   		<table id="tbl_datalist" class="tbl_datalist" cellpadding="0" cellspacing="0">
	   			<thead>
		   			<tr style="background-color: #43608c">
		   				<th class="txt_center" width="35" style="text-align: center;">序号</th>
		   				<th>部门编号</th>
		   				<th>部门名称</th>
		   				<th>部门简称</th>
		   				<th>上级部门</th>
		   				<th>人员总数</th>
		   				<th class="txt_center" style="width:100px;text-align: center">操作</th>
		   			</tr>
	   			</thead>
	   			<c:forEach var="data" items="${page.list}" varStatus="vs">
	   			<tr ondblclick="javascript:parent.openWin('dept/edit/${data.deptId}.html',0);" title="双击编辑部门信息">
	   				<td class="txt_center"  width="35" style="text-align: center;">${((page.pageIndex-1)*page.pageSize)+vs.count}</td>
	   				<td>${data.deptId}</td>
	   				<td class="name1" title="${data.name}">${data.name}</td>
	   				<td class="name1" title="${data.alias}">${data.alias}</td>
		   			<td class="name1" title="${data.parentName}">${data.parentName}</td>
		   			<td class="name1" >${data.userTotal}</td>
		   			<td class="txt_center" style="width:100px;">
						<img src="<c:url value='/resource/icon/edit.png'/>" onclick="parent.openWin('dept/edit/${data.deptId}.html',0);return false" title="编辑"/>
						<img src="<c:url value='/resource/icon/delete.png'/>" onclick="deleteDept('${data.deptId }','${data.parentId}');return false" title="删除"/>
					</td>
	   			</tr>
	   			</c:forEach>
	   		</table>
		</div>
	   	<div style="clear:both;"></div>
		<div id="div_nav" style="height:30px;line-height:30px;">
			<table style="width:100%;">
	   			<tr>
	   				<td style="text-align:center;">
						<table id="nav_tbl">
							<tr>
								<td>
									<c:if test="${page.previousPage}"><a onclick="goto_page(${page.pageIndex-1});">上一页 </a></c:if>
									<c:if test="${not page.previousPage}">上一页</c:if>
								</td>
						 		<c:forEach var="nav" items="${page.navigatePageNumbers}" varStatus="vs">
						 		<td><a onclick="goto_page(${page.navigatePageNumbers[vs.index]});" <c:if test="${page.pageIndex == page.navigatePageNumbers[vs.index]}">style="border:1px solid #1f2b62;font-weight:bold;"</c:if>>${page.navigatePageNumbers[vs.index]}</a></td>
						 		</c:forEach>
								<td>
							 		<c:if test="${not page.nextPage}">下一页</c:if>
							 		<c:if test="${page.nextPage}"><a onclick="goto_page(${page.pageIndex+1});">下一页 </a></c:if>
								</td>
								<td><input id="txt_page_index" type="text" value="${page.pageIndex}" size="5" maxlength="5" onblur="goto_page(eval('this.value>${page.totalPage}?${page.totalPage}:this.value<1?1:this.value'));" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/></td>
								<td style="width:120px;text-align:left;">&nbsp;第${page.pageIndex}页，共${page.totalPage}页<input type="hidden" value="${page.pageIndex}" id="_pg_curr_index"/></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>